package com.bee.beeAuth.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;
import java.util.Collection;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author 陈国松
 * @since 2022-10-09
 */
@Getter
@Setter
@EqualsAndHashCode
@TableName("sys_user")
@ApiModel(value = "SysUser对象", description = "用户表")
public class SysUser implements UserDetails {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("用户编号")
    @TableId(value = "id", type = IdType.ASSIGN_UUID)
    private String id;

    @ApiModelProperty("登录名称(用户名)")
    @TableField("username")
    private String username;

    @ApiModelProperty("登录密码")
    @TableField("password")
    private String password;

    @ApiModelProperty("帐户是否过期(1-未过期，0-已过期)")
    @TableField("is_account_non_expired")
    private Boolean accountNonExpired;

    @ApiModelProperty("帐户是否被锁定(1-未过期，0-已过期)")
    @TableField("is_account_non_locked")
    private Boolean accountNonLocked;

    @ApiModelProperty("密码是否过期(1-未过期，0-已过期)")
    @TableField("is_credentials_non_expired")
    private Boolean credentialsNonExpired;

    @ApiModelProperty("帐户是否可用(1-可用，0-禁用)")
    @TableField("is_enabled")
    private Boolean enabled;

    @ApiModelProperty("真实姓名")
    @TableField("real_name")
    private String realName;

    @ApiModelProperty("昵称")
    @TableField("nick_name")
    private String nickName;

    @ApiModelProperty("所属部门ID")
    @TableField("department_id")
    private String departmentId;

    @ApiModelProperty("所属部门名称")
    @TableField("department_name")
    private String departmentName;

    @ApiModelProperty("性别(0-男，1-女)")
    @TableField("gender")
    private Boolean gender;

    @ApiModelProperty("电话")
    @TableField("phone")
    private String phone;

    @ApiModelProperty("邮箱")
    @TableField("email")
    private String email;

    @ApiModelProperty("用户头像")
    @TableField("avatar")
    private String avatar;

    @ApiModelProperty("是否是管理员(1-管理员)")
    @TableField("is_admin")
    private Boolean admin;

    @ApiModelProperty("创建人")
    @TableField("create_user")
    private String createUser;

    @ApiModelProperty("创建时间")
    @TableField("create_time")
    private LocalDateTime createTime;

    @ApiModelProperty("修改人")
    @TableField("update_user")
    private String updateUser;

    @ApiModelProperty("修改时间")
    @TableField("update_time")
    private LocalDateTime updateTime;

    @ApiModelProperty("备注")
    @TableField("remark")
    private String remark;

    @ApiModelProperty("排序")
    @TableField("order_num")
    private Integer orderNum;

    @ApiModelProperty("是否删除(0-未删除，1-已删除)")
    @TableField("is_deleted")
    @TableLogic
    private Boolean deleted;

    /**
     * 权限列表
     */
    @TableField(exist = false)
    private Collection<? extends GrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return accountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return credentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }
}
